//
//#include "../../raknet/source/RakPeerInterface.h"
//#include "../../raknet/source/RakNetworkFactory.h"
//#include <stdio.h>
//#include "../../raknet/source/Kbhit.h"
//#include <string.h>
//#include <stdlib.h>
//#include "../../raknet/source/BitStream.h"
//#include "../../raknet/source/MessageIdentifiers.h"
//#include "../../raknet/source/StringCompressor.h"
//#include "../../raknet/source/RakSleep.h"
//#include "../../raknet/source/NetworkIDObject.h"
//#include "../../raknet/source/AutoRPC.h"
//#include "../../raknet/source/NetworkIDManager.h"
//#include "../../raknet/source/GetTime.h"
//
//struct ThreeBytes
//{
//	char bytes[3];
//};
//struct TwentyBytes
//{
//	char bytes[20];
//};
//
//using namespace RakNet;
//
//AutoRPC autoRpc;
//
//// AutoRPC has the restriction that NetworkIDObject must be the basemost derived class
//// Use RPC3 to get around this restriction
//class BaseClass : public NetworkIDObject
//{
//public:
//	virtual int AUTO_RPC_CALLSPEC objectMemberFunc(int a, const char *str, AutoRPC* networkCaller) {printf("Shouldn't see this"); return 0;}
//};
//
//class MultipleInheritance
//{
//public:
//	MultipleInheritance() {a=1234;}
//	int a;
//};
//
//class DerivedClass : public MultipleInheritance, public BaseClass
//{
//public:
//	DerivedClass() {memberVariable=12;}
//	~DerivedClass() {}
//
//	virtual int AUTO_RPC_CALLSPEC objectMemberFunc(int a, const char *str, AutoRPC* networkCaller) {
//		if (networkCaller==0)
//		{
//			autoRpc.SetRecipientObject(GetNetworkID());
//			autoRpc.Call("DerivedClass::objectMemberFunc",a, str);
//			autoRpc.SetRecipientObject(UNASSIGNED_NETWORK_ID);
//		}
//		else
//		{
//			printf("%s\n", str);
//		}
//		printf("object member a=%i memberVariable=%i sender=%s\n", a, memberVariable, networkCaller==0 ? "N/A" : networkCaller->GetLastSenderAddress().ToString());
//		return 0;
//	}
//
//	int memberVariable;
//};
//
//int main(void)
//{
//	RakPeerInterface *rakPeer;
//	
//	RakNetTime stage2=0;
//	NetworkIDManager networkIDManager;
//	networkIDManager.SetIsNetworkIDAuthority(true);
//	autoRpc.SetNetworkIDManager(&networkIDManager);
//	DerivedClass derivedClass;
//	NetworkID idZero;
//	unsigned short sysad = 2;
//	idZero.localSystemAddress=sysad;
//	derivedClass.SetNetworkIDManager(&networkIDManager);
//	derivedClass.SetNetworkID(idZero);
//
//	derivedClass.GetNetworkIDManager();
//
//	printf("Demonstration of the AutoRPC plugin.\n");
//	printf("It is similar to Raknet's RPC system, but automatically\n");
//	printf("serializes and deserializes the parameters to the function call\n");
//	printf("On Linux compile with -Wno-pmf-conversions.\n");
//	printf("-- DEPRECIATED -- Use RPC3 if possible.\n");
//	printf("Difficulty: Intermediate\n\n");
//
//	printf("(S)erver or (C)lient?: ");
//	bool isServer;
//	char str[256];
//	gets(str);
//	if (str[0]=='s' || str[0]=='S')
//		isServer=true;
//	else
//		isServer=false;
//
//	rakPeer = RakNetworkFactory::GetRakPeerInterface();
//	if (isServer)
//	{
//		SocketDescriptor socketDescriptor(50000,0);
//		rakPeer->Startup(10, 30, &socketDescriptor, 1);
//		rakPeer->SetMaximumIncomingConnections(10);
//		printf("Server started.\n");
//	}
//	else
//	{
//		SocketDescriptor socketDescriptor(0,0);
//		rakPeer->Startup(1, 30, &socketDescriptor, 1);
//
//		ARPC_REGISTER_CPP_FUNCTION3(&autoRpc, "DerivedClass::objectMemberFunc", int, BaseClass, objectMemberFunc, int a, const char *str, AutoRPC* networkCaller);
//
//		// Send out a LAN broadcast to find other instances on the same computer
//		rakPeer->Ping( "255.255.255.255", 50000, true, 0 );
//
//		printf("Client started. Will automatically connect to running servers.\n");
//	}
//	rakPeer->AttachPlugin(&autoRpc);
//	
//	Packet *p;
//	while (1)
//	{
//		for (p=rakPeer->Receive(); p; rakPeer->DeallocatePacket(p), p=rakPeer->Receive())
//		{
//			switch (p->data[0])
//			{
//			case ID_DISCONNECTION_NOTIFICATION:
//				printf("ID_DISCONNECTION_NOTIFICATION\n");
//				break;
//			case ID_ALREADY_CONNECTED:
//				printf("ID_ALREADY_CONNECTED\n");
//				break;
//			case ID_CONNECTION_ATTEMPT_FAILED:
//				printf("Connection attempt failed\n");
//				break;
//			case ID_NO_FREE_INCOMING_CONNECTIONS:
//				printf("ID_NO_FREE_INCOMING_CONNECTIONS\n");
//				break;
//			case ID_PONG:
//				// Found the server
//				rakPeer->Connect(p->systemAddress.ToString(false),p->systemAddress.port,0,0,0);
//				break;
//			case ID_CONNECTION_REQUEST_ACCEPTED:
//				// This tells the client they have connected
//				printf("ID_CONNECTION_REQUEST_ACCEPTED\n");
//				break;
//			case ID_NEW_INCOMING_CONNECTION:
//				// Directed send, default is broadcast
//			//	autoRpc.SetRecipientAddress(p->systemAddress,false);
//				// A new client connected, call all the functions, which should be mirrored to all clients
//				derivedClass.objectMemberFunc(999, "Hello world 1", 0);
//				stage2=RakNet::GetTime()+500;
//				break;
//			case ID_RPC_REMOTE_ERROR:
//				{
//					// Receipient system returned an error
//					switch (p->data[1])
//					{
//					case RPC_ERROR_NETWORK_ID_MANAGER_UNAVAILABLE:
//						printf("RPC_ERROR_NETWORK_ID_MANAGER_UNAVAILABLE\n");
//						break;
//					case RPC_ERROR_OBJECT_DOES_NOT_EXIST:
//						printf("RPC_ERROR_OBJECT_DOES_NOT_EXIST\n");
//						break;
//					case RPC_ERROR_FUNCTION_INDEX_OUT_OF_RANGE:
//						printf("RPC_ERROR_FUNCTION_INDEX_OUT_OF_RANGE\n");
//						break;
//					case RPC_ERROR_FUNCTION_NOT_REGISTERED:
//						printf("RPC_ERROR_FUNCTION_NOT_REGISTERED\n");
//						break;
//					case RPC_ERROR_FUNCTION_NO_LONGER_REGISTERED:
//						printf("RPC_ERROR_FUNCTION_NO_LONGER_REGISTERED\n");
//						break;
//					case RPC_ERROR_CALLING_CPP_AS_C:
//						printf("RPC_ERROR_CALLING_CPP_AS_C\n");
//						break;
//					case RPC_ERROR_CALLING_C_AS_CPP:
//						printf("RPC_ERROR_CALLING_C_AS_CPP\n");
//						break;
//					case RPC_ERROR_STACK_TOO_SMALL:
//						printf("RPC_ERROR_STACK_TOO_SMALL\n");
//						break;
//					case RPC_ERROR_STACK_DESERIALIZATION_FAILED:
//						printf("RPC_ERROR_STACK_DESERIALIZATION_FAILED\n");
//						break;
//					case RPC_ERROR_INCORRECT_NUMBER_OF_PARAMETERS:
//						printf("RPC_ERROR_INCORRECT_NUMBER_OF_PARAMETERS\n");
//						break;
//					}
//
//					char outputBuff[256];
//					stringCompressor->DecodeString(outputBuff,256,&RakNet::BitStream(p->data+sizeof(MessageID)+1,p->length-sizeof(MessageID)-1,false),0);
//					printf("Function: %s\n", outputBuff);
//				}
//			}
//		}
//
//		if (stage2 && stage2 < RakNet::GetTime())
//		{
//			stage2=0;
//			derivedClass.objectMemberFunc(999, "Hello world 2", 0);			
//		}
//
//		RakSleep(0);
//	}
//	
//	rakPeer->Shutdown(100,0);
//	RakNetworkFactory::DestroyRakPeerInterface(rakPeer);
//
//	return 1;
//}

// *
// * main.cpp
// *
// *  Created on: 26.04.2009
// *      Author: markus
// */

#include <QtGui/QApplication>
#include "../GUI/mainwindow.h"

#ifndef __gnu_linux__
//#include "windows.h"
#endif
#include "../src/CManageNetwork.h"
//#include <stdio>

//INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT)
int main(int argc, char *argv[])
{
	//QStuff
	QApplication a(argc, argv);
	MainWindow m;
	m.show();
	a.exec();

	CManageNetworkSingle::getInstance()->~CManageNetworkSingle();
	return 0;
}



